package com.qf.controller;




import com.qf.pojo.Student;
import com.qf.service.StudentService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @GetMapping("/selectAllStudent")
    public ResultMsg selectAllStudent(@RequestParam(required = false, defaultValue = "") String name, @RequestParam(required = false, defaultValue = "-1") Integer studentId, @RequestParam(required = false, defaultValue = "-1") Integer studentStatus, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit) {
        return studentService.selectAllStudent(name,studentId,studentStatus,page,limit);
    }
    @GetMapping("/selectOneStudent")
    public ResultMsg selectOneStudent(@RequestParam(required = false) Integer studentId) {
        ResultMsg resultMsg = studentService.selectOneStudent(studentId);
        return resultMsg;
    }

    @PutMapping("/updateStudent")
    public ResultMsg updateStudent(@RequestBody Student student) {
        return studentService.updateStudent(student);
    }

    @PutMapping("/insertStudent")
    public ResultMsg insertStudent(@RequestBody Student student) {
        return studentService.insertStudent(student);
    }

    @PutMapping("/updateStudentStatus")
    public ResultMsg updateStudentStatus(@RequestBody Map<String, Object> map) {
        return studentService.updateStudentStatus((List<Integer>) map.get("studentIds"), (Integer) map.get("studentStatus"));
    }

    @DeleteMapping("/deleteStudent")
    public ResultMsg deleteStudent(@RequestBody Map<String, List<Integer>> map){
        return studentService.deleteStudent(map.get("studentIds"));
    }
}

